package io.awen.modules.sign.controller;

import io.awen.common.utils.PageUtils;
import io.awen.common.utils.R;
import io.awen.modules.sign.entity.SignCarEntity;
import io.awen.modules.sign.entity.SignCarLonLatEntity;
import io.awen.modules.sign.service.SignCarLonLatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 收运单位车辆经纬度记录表
 *
 * @author liu.wen
 * @email liu.wen@qq.com
 * @date 2022-08-10 00:47:08
 */
@RestController
@RequestMapping("sign/signcarlonlat")
public class SignCarLonLatController {
    @Autowired
    private SignCarLonLatService signCarLonLatService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = signCarLonLatService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 获取某辆车某天的形式轨迹
     *
     * @return
     */
    @RequestMapping("/getListByCarIdAndDate") //sign/signcarlonlat/getListByCarIdAndDate
    public R getListByCarIdAndDate(@RequestParam Long carId, String startDate, String endDate) {
        List<SignCarLonLatEntity> list = signCarLonLatService.getListByCarIdAndDate(carId, startDate, endDate);

        return R.ok().put("list", list);
    }


    @RequestMapping("/getCarLoc")
    public R getCarLoc(SignCarEntity entity) {
        SignCarLonLatEntity lonLatEntity = signCarLonLatService.getCarLoc(entity);

        return R.ok().put("lonLat", lonLatEntity);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sign:signcarlonlat:info")
    public R info(@PathVariable("id") Long id) {
        SignCarLonLatEntity signCarLonLat = signCarLonLatService.getById(id);

        return R.ok().put("signCarLonLat", signCarLonLat);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sign:signcarlonlat:save")
    public R save(@RequestBody SignCarLonLatEntity signCarLonLat) {
        signCarLonLatService.save(signCarLonLat);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sign:signcarlonlat:update")
    public R update(@RequestBody SignCarLonLatEntity signCarLonLat) {
        signCarLonLatService.updateById(signCarLonLat);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sign:signcarlonlat:delete")
    public R delete(@RequestBody Long[] ids) {
        signCarLonLatService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
